<block name="content">
    <form class="layui-form inline-form">
        <div class="pull-left">
            <div class="layui-inline dropdown">
                <select name="status" lay-search lay-filter="status">
                    <option value="">选择{$model_name}状态</option>
                    <volist name="model_status" id="vo" key="k">
                        <option value="{$k}"> {$vo}</option>
                    </volist>
                </select>
            </div>
            <div class="layui-inline dropdown">
                <input name="title" class="layui-input" type="text" id="storiestitle" placeholder="{$model_name}名称">
            </div>
            <div class="layui-inline">
                <button class="layui-btn  " lay-submit lay-filter="search_btn"><i
                        class="layui-icon">&#xe615;</i>搜索
                </button>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layui-btn-warm ajax-form"
                        data-url="{:url('storiesadd?project_id='.$project_id.'&model_id='.$model_id)}"
                ><i class="layui-icon">&#xe61f;</i> 新增{$model_name}
                </button>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layui-btn-normal  ajax-form"
                        data-url="{:url('category?project_id='.$project_id.'&model_id='.$model_id)}"
                        tree-url="{:url('treecategory?project_id='.$project_id.'&model_id='.$model_id)}"><i
                        class="layui-icon">&#xe620;</i>管理{$model_name}分类
                </button>
            </div>
        </div>
    </form>

    <div class="layui-row">
        <div class="layui-col-md2">
            <div class="layui-card">
                <div class="layui-card-header">{$model_name}分类</div>
                <div class="layui-card-body">
                    <div id="category"></div>
                </div>
            </div>

        </div>
        <div class="layui-col-md10">
            <table class="layui-table text-center" id="list" lay-filter="list"
                   list-url="{:url('storieslists?project_id='.$project_id.'&model_id='.$model_id)}"
                   edit-url="{:url('editform?project_id='.$project_id.'&model_id='.$model_id)}"
                   assigned-url="{:url('editcategory?project_id='.$project_id.'&model_id='.$model_id)}"
                   del-url="{:url('delete?project_id='.$project_id.'&model_id='.$model_id)}"
            ></table>
        </div>
    </div>


</block>

<block name="script">
    <script type="text/html" id="barDemo">
        <a class="layui-btn  layui-btn-xs" lay-event="applyinfo"
           info_id="{:url('storieswork?project_id='.$project_id.'&model_id='.$model_id)}"><i
                class="fa fa-laptop"></i>处理</a>
        <a class="layui-btn  layui-btn-xs " lay-event="edit"><i class="fa fa-pencil"></i> 编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete"> <i class="fa fa-trash-o"></i> 删除</a>
    </script>
    <script type="text/javascript">
        layui.use(['element', 'table', 'form', 'tree'], function () {
            var table = layui.table
                , element = layui.element
                , form = layui.form
                , tree = layui.tree;
            table.render({
                elem: '#list'
                , url: "{:url('storieslists?project_id='.$project_id.'&model_id='.$model_id)}"
                , page: true
                , loading: true
                ,limit:20
                , cols: [[
                     {field: 'level_id', width: 60, title: '等级'}
                    , {field: 'title', title: '{$model_name}名称', edit: 'text'}
                    , {field: 'uidnickname', width: 85, title: '发布人'}
                    , {field: 'touidnickname', width: 85, title: '完成人员'}
                    , {field: 's_time', width: 75, title: '开始'}
                    , {field: 'e_time', width: 75, title: '结束'}
                    , {field: 'p_time', width: 80, title: '计划',align:'right'}
                    , {field: 'w_time', width: 80, title: '实际',align:'right'}
                    , {field: 'status', width: 70, title: '状态'}
                    , {fixed: 'right', width: 200, title: '操作', toolbar: '#barDemo'}
                ]]
            });

            function treecategory() {
                $.ajax({
                    url: "{:url('treecategory?project_id='.$project_id.'&model_id='.$model_id)}",
                    type: 'get',
                    dataType: 'json',
                })
                    .done(function (res) {
                        if (res.data == null) {
                            layer.msg('没有内容', {
                                time: 1500,
                                icon: 5
                            });
                        } else {
                            tree.render({
                                elem: '#category'  //绑定元素
                                , id: 'category'
                                , data: res.data
                                , click: function (obj) {
                                    console.log(obj.data)
                                    table.reload('list', {
                                        url: "{:Url('storieslists?project_id='.$project_id.'&model_id='.$model_id)}"
                                        , page: {
                                            curr: 1
                                        }
                                        , where: {
                                            category: obj.data.id,
                                        }
                                    });
                                    return false;
                                }
                            });
                        }
                    })
                    .fail(function () {
                        layer.msg('服务器异常', {
                            time: 1500,
                            icon: 5
                        });
                    })
                    .always(function () {

                    });

            }

            treecategory();

            form.render();
            form.on('submit(docsearch_btn)', function (data) {
                table.reload('doclist', {
                    url: "{:Url('project/docadmin/doclists?project_id='.$project_id)}"
                    , page: {
                        curr: 1
                    }
                    , where: data.field
                });
                return false;
            });
            form.on('select(doc_type)', function (data) {
                table.reload('doclist', {
                    url: "{:Url('project/docadmin/doclists?project_id='.$project_id)}"
                    , page: {
                        curr: 1
                    }
                    , where: {
                        status: data.value
                    }
                });
                return false;
            });


        });
    </script>
</block>
